package net.jueb.frameworkDemo.orm.mysql.mybatis.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import net.jueb.frameworkDemo.orm.entity.Role;

public interface RoleMapper {

	public final static String TABLE_NAME="t_role";
	
	public final String CannonsTypeHandler="net.jueb.jseTest.db.mybatis.typeHandler.CannonsTypeHandler";
	
	@Select("select max(id) from "+TABLE_NAME+"")
	public int getMaxRoleId();
	
	@Options(useGeneratedKeys=true,keyProperty="id")
    @Insert("insert into "+TABLE_NAME+"("
    		+ "id,uid,pn,name,money,diamond,phoneMoney,level,exp,rechargeAmount,sex,pwd,cellPhone,"
    		+ "status,createTime,lastLogin,faceIcon,isRobot,maxBetId,currentCannon,cannons,monthCardTime,lastMonthCardTime"
    		+ ") "
    		+ "values("
    		+ "#{id},#{uid},#{pn},#{name},#{money},#{diamond},#{phoneMoney},#{level},#{exp},#{rechargeAmount},#{sex},#{pwd},#{cellPhone},"
    		+ "#{status},#{createTime},#{lastLogin},#{faceIcon},#{isRobot},#{maxBetId},#{currentCannon},#{cannons,typeHandler="+CannonsTypeHandler+"},"
    		+ "#{monthCardTime},#{lastMonthCardTime}"
    		+ ")")  
    public int insert(Role role);  
      
    @Update("update "+TABLE_NAME+" set uid=#{uid},name = #{name},pn = #{pn}, "
    		+ "money = #{money}, diamond = #{diamond}, phoneMoney = #{phoneMoney},level = #{level}, exp = #{exp},rechargeAmount = #{rechargeAmount},"
    		+ "sex = #{sex},pwd = #{pwd},cellPhone = #{cellPhone},status = #{status},"
    		+ "createTime = #{createTime},lastLogin = #{lastLogin},faceIcon=#{faceIcon},isRobot = #{isRobot},maxBetId=#{maxBetId},currentCannon=#{currentCannon},cannons=#{cannons,typeHandler="+CannonsTypeHandler+"},"
    		+ "monthCardTime = #{monthCardTime},lastMonthCardTime = #{lastMonthCardTime}"
    		+ " where id = #{id}")  
    public int update(Role role);
      
    @Select("select * from "+TABLE_NAME+" where id = #{id}")
    public Role findRoleById(long id); 
    
    @Select("select * from "+TABLE_NAME+" where pn=#{pn} and uid = #{uid}")
    public Role findRoleByUid(@Param("pn")String pn,@Param("uid")String uid); 
    
    @Select("select * from "+TABLE_NAME+" where pn=#{pn} and name = #{name}")  
    public Role findRoleByName(@Param("pn")String pn,@Param("name")String name); 
    
    @Delete("delete from "+TABLE_NAME+" where id = #{id}")  
    public int deleteById(long id); 
    
    @Delete("delete * from "+TABLE_NAME)  
    public int deleteAll(); 
      
    @Select("select * from "+TABLE_NAME+"")  
    public List<Role> findAll(); 
    
    @Select("select * from "+TABLE_NAME+" where isRobot = 1")  
    public List<Role> findAllRobots(); 
}
